package com.czk.server;

import com.czk.codec.ObjDecoder;
import com.czk.codec.ObjEncoder;
import com.czk.domain.TransferProtocol;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/4/26 11:03
 */
@Component
public class MyChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Autowired
    private MyNettyServerHandler myNettyServerHandler;

    @Override
    protected void initChannel(SocketChannel channel) throws Exception {
        ChannelPipeline pipeline = channel.pipeline();
        pipeline.addLast(new ObjDecoder(TransferProtocol.class));
        pipeline.addLast(new ObjEncoder(TransferProtocol.class));
        pipeline.addLast(myNettyServerHandler);
    }
}
